package com.wpre.lotterysystem.service.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

import static com.wpre.lotterysystem.common.config.DirectRabbitConfig.*;

/**
 * Created with IntelliJ IDEA.
 * Description: 处理死性队列的消息
 * User: LianBao
 * Date: 2024-12-26
 * Time: 14:26
 */
@RabbitListener(queues = DLX_QUEUE_NAME) //监听者,监听的队列
@Component
@Slf4j
public class DlxReceiver {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    @RabbitHandler
    public void process(Map<String, String> message) {
        log.info("{开始处理异常消息}", message);
        //接收异常消息
        //将异常消息存储到数据库
        rabbitTemplate.convertAndSend(EXCHANGE_NAME, ROUTING, message);
    }
}
